home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 10 / AACD 10.iso / AACD / Games / MAME / src / vidhrdw / troangel.c < prev    next >
C/C++ Source or Header  |  2000-04-04  |  6KB  |  237 lines

  1. #include "driver.h"
  2. #include "vidhrdw/generic.h"
  3.  
  4.  
  5. unsigned char *troangel_scroll;
  6.  
  7. static int flipscreen;
  8.  
  9.  
  10. /***************************************************************************
  11.  
  12.   Convert the color PROMs into a more useable format.
  13.  
  14.   Tropical Angel has two 256x4 character palette PROMs, one 32x8 sprite
  15.   palette PROM, and one 256x4 sprite color lookup table PROM.
  16.  
  17.   I don't know for sure how the palette PROMs are connected to the RGB
  18.   output, but it's probably something like this; note that RED and BLUE
  19.   are swapped wrt the usual configuration.
  20.  
  21.   bit 7 -- 220 ohm resistor  -- RED
  22.         -- 470 ohm resistor  -- RED
  23.         -- 220 ohm resistor  -- GREEN
  24.         -- 470 ohm resistor  -- GREEN
  25.         -- 1  kohm resistor  -- GREEN
  26.         -- 220 ohm resistor  -- BLUE
  27.         -- 470 ohm resistor  -- BLUE
  28.   bit 0 -- 1  kohm resistor  -- BLUE
  29.  
  30. ***************************************************************************/
  31. void troangel_vh_convert_color_prom(unsigned char *palette, unsigned short *colortable,const unsigned char *color_prom)
  32. {
  33.     int i;
  34.     #define TOTAL_COLORS(gfxn) (Machine->gfx[gfxn]->total_colors * Machine->gfx[gfxn]->color_granularity)
  35.     #define COLOR(gfxn,offs) (colortable[Machine->drv->gfxdecodeinfo[gfxn].color_codes_start + offs])
  36.  
  37.  
  38.     /* character palette */
  39.     for (i = 0;i < 256;i++)
  40.     {
  41.         int bit0,bit1,bit2;
  42.  
  43.  
  44.         /* red component */
  45.         bit0 = 0;
  46.         bit1 = (color_prom[256] >> 2) & 0x01;
  47.         bit2 = (color_prom[256] >> 3) & 0x01;
  48.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  49.         /* green component */
  50.         bit0 = (color_prom[0] >> 3) & 0x01;
  51.         bit1 = (color_prom[256] >> 0) & 0x01;
  52.         bit2 = (color_prom[256] >> 1) & 0x01;
  53.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  54.         /* blue component */
  55.         bit0 = (color_prom[0] >> 0) & 0x01;
  56.         bit1 = (color_prom[0] >> 1) & 0x01;
  57.         bit2 = (color_prom[0] >> 2) & 0x01;
  58.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  59.  
  60.         COLOR(0,i) = i;
  61.         color_prom++;
  62.     }
  63.  
  64.     color_prom += 256;
  65.     /* color_prom now points to the beginning of the sprite palette */
  66.  
  67.  
  68.     /* sprite palette */
  69.     for (i = 0;i < 16;i++)
  70.     {
  71.         int bit0,bit1,bit2;
  72.  
  73.  
  74.         /* red component */
  75.         bit0 = 0;
  76.         bit1 = (*color_prom >> 6) & 0x01;
  77.         bit2 = (*color_prom >> 7) & 0x01;
  78.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  79.         /* green component */
  80.         bit0 = (*color_prom >> 3) & 0x01;
  81.         bit1 = (*color_prom >> 4) & 0x01;
  82.         bit2 = (*color_prom >> 5) & 0x01;
  83.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  84.         /* blue component */
  85.         bit0 = (*color_prom >> 0) & 0x01;
  86.         bit1 = (*color_prom >> 1) & 0x01;
  87.         bit2 = (*color_prom >> 2) & 0x01;
  88.         *(palette++) = 0x21 * bit0 + 0x47 * bit1 + 0x97 * bit2;
  89.  
  90.         color_prom++;
  91.     }
  92.  
  93.     color_prom += 16;
  94.     /* color_prom now points to the beginning of the sprite lookup table */
  95.  
  96.  
  97.     /* sprite lookup table */
  98.     for (i = 0;i < TOTAL_COLORS(1);i++)
  99.     {
  100.         COLOR(1,i) = 256 + (~*color_prom & 0x0f);
  101.         color_prom++;
  102.     }
  103. }
  104.  
  105.  
  106.  
  107. WRITE_HANDLER( troangel_flipscreen_w )
  108. {
  109.     /* screen flip is handled both by software and hardware */
  110.     data ^= ~readinputport(4) & 1;
  111.  
  112.     if (flipscreen != (data & 1))
  113.     {
  114.         flipscreen = data & 1;
  115.         memset(dirtybuffer,1,videoram_size);
  116.     }
  117.  
  118.     coin_counter_w(0,data & 0x02);
  119.     coin_counter_w(1,data & 0x20);
  120. }
  121.  
  122.  
  123.  
  124.  
  125. static void draw_background( struct osd_bitmap *bitmap )
  126. {
  127.     int offs;
  128.     const struct GfxElement *gfx = Machine->gfx[0];
  129.  
  130.     for (offs = videoram_size - 2;offs >= 0;offs -= 2)
  131.     {
  132.         if (dirtybuffer[offs] || dirtybuffer[offs+1])
  133.         {
  134.             int sx,sy,code,attr,flipx;
  135.  
  136.  
  137.             dirtybuffer[offs] = dirtybuffer[offs+1] = 0;
  138.  
  139.             sx = (offs/2) % 32;
  140.             sy = (offs/2) / 32;
  141.  
  142.             attr = videoram[offs];
  143.             code = videoram[offs+1] + ((attr & 0xc0) << 2);
  144.             flipx = attr & 0x20;
  145.  
  146.             if (flipscreen)
  147.             {
  148.                 sx = 31 - sx;
  149.                 sy = 31 - sy;
  150.                 flipx = !flipx;
  151.             }
  152.  
  153.             drawgfx(tmpbitmap,gfx,
  154.                 code,
  155.                 attr & 0x1f,
  156.                 flipx,flipscreen,
  157.                 8*sx,8*sy,
  158.                 0,TRANSPARENCY_NONE,0);
  159.         }
  160.     }
  161.  
  162.     {
  163.         int xscroll[256];
  164.  
  165.         if (flipscreen)
  166.         {
  167.             /* fixed */
  168.             for (offs = 0;offs < 64;offs++) xscroll[255-offs] = 0;
  169.  
  170.             /* scroll (wraps around) */
  171.             for (offs = 64;offs < 128;offs++) xscroll[255-offs] = troangel_scroll[64];
  172.  
  173.             /* linescroll (no wrap) */
  174.             for (offs = 128;offs < 256;offs++) xscroll[255-offs] = troangel_scroll[offs];
  175.         }
  176.         else
  177.         {
  178.             /* fixed */
  179.             for (offs = 0;offs < 64;offs++) xscroll[offs] = 0;
  180.  
  181.             /* scroll (wraps around) */
  182.             for (offs = 64;offs < 128;offs++) xscroll[offs] = -troangel_scroll[64];
  183.  
  184.             /* linescroll (no wrap) */
  185.             for (offs = 128;offs < 256;offs++) xscroll[offs] = -troangel_scroll[offs];
  186.         }
  187.  
  188.         copyscrollbitmap(bitmap,tmpbitmap,256,xscroll,0,0,&Machine->drv->visible_area,TRANSPARENCY_NONE,0);
  189.     }
  190. }
  191.  
  192. static void draw_sprites( struct osd_bitmap *bitmap )
  193. {
  194.     int offs;
  195.  
  196.  
  197.     for (offs = spriteram_size-4;offs >= 0;offs -= 4)
  198.     {
  199.         unsigned char attributes = spriteram[offs+1];
  200.         int sx = spriteram[offs+3];
  201.         int sy = ((224-spriteram[offs+0]-32)&0xff)+32;
  202.         int code = spriteram[offs+2];
  203.         int color = attributes&0x1f;
  204.         int flipy = attributes&0x80;
  205.         int flipx = attributes&0x40;
  206.  
  207.         int tile_number = code & 0x3f;
  208.  
  209.         int bank = 0;
  210.         if( code&0x80 ) bank += 1;
  211.         if( attributes&0x20 ) bank += 2;
  212.  
  213.         if (flipscreen)
  214.         {
  215.             sx = 240 - sx;
  216.             sy = 224 - sy;
  217.             flipx = !flipx;
  218.             flipy = !flipy;
  219.         }
  220.  
  221.         drawgfx(bitmap,Machine->gfx[1+bank],
  222.             tile_number,
  223.             color,
  224.             flipx,flipy,
  225.             sx,sy,
  226.             &Machine->drv->visible_area,TRANSPARENCY_PEN,0);
  227.     }
  228. }
  229.  
  230.  
  231.  
  232. void troangel_vh_screenrefresh(struct osd_bitmap *bitmap,int full_refresh)
  233. {
  234.     draw_background(bitmap);
  235.     draw_sprites(bitmap);
  236. }
  237.